home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 November
/
PCWorld_2006-11_cd.bin
/
domacnost a kancelar
/
findgraph
/
fgraph.exe
/
{app}
/
TestVC
/
MainDoc.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2002-08-09
|
4KB
|
168 lines
// MainDoc.cpp : implementation of the CMainDoc class
// From MFC\OLE\OCLIENT
// Difference:
// use COleDocument not COleLinkingDoc
// unuse ID_OLE_EDIT_CONVERT, ID_OLE_EDIT_LINKS, ID_EDIT_PASTE_LINK, ID_EDIT_PASTE
#include "stdafx.h"
#include "Crov.h"
#include "MainDoc.h"
#include "RectItem.h"
#include "MainView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// private clipboard format
CLIPFORMAT CMainDoc::m_cfPrivate = NULL;
/////////////////////////////////////////////////////////////////////////////
// CMainDoc
IMPLEMENT_DYNCREATE(CMainDoc, COleDocument)
BEGIN_MESSAGE_MAP(CMainDoc, COleDocument)
//{{AFX_MSG_MAP(CMainDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Enable default OLE container implementation
ON_UPDATE_COMMAND_UI_RANGE(ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, COleDocument::OnUpdateObjectVerbMenu)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainDoc construction/destruction
CMainDoc::CMainDoc() : m_sizeDoc(800,1050) // document size is 8x10.5
{
// Use OLE compound files
EnableCompoundFile();
m_bNeedUpdate = TRUE;
if (m_cfPrivate == NULL)
m_cfPrivate = (CLIPFORMAT)
::RegisterClipboardFormat(_T("MFC OClient Sample"));
}
CMainDoc::~CMainDoc()
{
}
CSize &CMainDoc::GetDocumentSize()
{
return m_sizeDoc;
}
BOOL CMainDoc::OnNewDocument()
{
if (!COleDocument::OnNewDocument())
return FALSE;
//deactivate all objects in all views
POSITION posView = GetFirstViewPosition();
ASSERT( posView != NULL );
CMainView* pView = DYNAMIC_DOWNCAST(CMainView, GetNextView(posView));
pView->UnSelect();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainDoc item management
CRectItem* CMainDoc::CreateItem()
{
return new CRectItem(this); // does 'AddItem' automatically
}
// safe delete that notifies views
void CMainDoc::DeleteItem(CRectItem* pItem)
{
ASSERT(pItem->GetDocument() == this);
SetModifiedFlag();
UpdateAllViews(NULL, 1, pItem); // pItem will be deleted
pItem->Delete(); // does a 'RemoveItem' & 'delete this' automatically
}
// used in View: paste
void CMainDoc::AdjustItemPosition(CRectItem* pItem)
{
POSITION pos = GetStartPosition();
while (pos != NULL)
{
CRectItem* pRectItem = (CRectItem*)GetNextItem(pos);
ASSERT_KINDOF(CRectItem, pItem);
if (pRectItem != pItem && pRectItem->GetRect() == pItem->GetRect())
{
pItem->m_ptPos.x += 10;
pItem->m_ptPos.y -= 10;
pos = GetStartPosition();
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CMainDoc serialization
void CMainDoc::Serialize(CArchive& ar)
{
// NOTE: New easier to use serialization model -- even for OLE objects!
WORD wMagic = 0x0DAF;
if (ar.IsStoring())
{
if (HasBlankItems() &&
AfxMessageBox(IDP_SAVEINCOMPLETE, MB_YESNO|MB_ICONQUESTION) != IDYES)
{
TRACE0("Aborting save -- incomplete items found!\n");
AfxThrowArchiveException(CArchiveException::generic);
}
ar << wMagic;
}
else
{
WORD w;
ar >> w;
if (w != wMagic)
{
TRACE0("invalid magic number at start of file\n");
AfxThrowArchiveException(CArchiveException::generic);
}
}
// Calling the base class COleDocument enables serialization
// of the container document's COleClientItem objects.
COleDocument::Serialize(ar);
// COleLinkingDoc::Serialize(ar);
}
/////////////////////////////////////////////////////////////////////////////
// CMainDoc diagnostics
#ifdef _DEBUG
void CMainDoc::AssertValid() const
{
COleDocument::AssertValid();
}
void CMainDoc::Dump(CDumpContext& dc) const
{
COleDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainDoc commands